package com.ilancuo.proxy.test;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class UserDynamicProxy implements InvocationHandler {
    private User o;

    public UserDynamicProxy(User o) {
        this.o = o;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("账号密码检测");
        method.invoke(o, args);
        System.out.println("欢迎登录");
        return null;
    }

    public static void main(String[] args) {
        User o = (User) Proxy.newProxyInstance(User.class.getClassLoader(),
                new Class[]{User.class}, new UserDynamicProxy(new UserImpl()));
        o.login();
    }
}
